Feat/two phase memory extraction#106
Open
yuanhechen wants to merge 5 commits intoEverMind-AI:mainfrom
Open
Conversation
added 5 commits
March 2, 2026 17:51
将 MEMORY_LANGUAGE 由 en 改为 zh,使 EverMemOS 在提取 情节记忆、前瞻规划、事件日志等记忆时使用中文 prompt, 避免 LLM 输出英文导致记忆内容中英文混杂。
问题:DELETE /api/v1/memories 只对 MongoDB MemCell 做软删除, 未清理 Milvus 向量索引,导致清空记忆后向量召回仍然返回已删除内容。 根本原因:记忆存储是双写(MongoDB + Milvus),但删除只有 MongoDB 一侧,Milvus 侧向量始终存在,向量搜索完全感知不到软删除标记。 修复方案(在 delete_by_combined_criteria 末尾新增步骤 7): - 新增私有方法 _delete_milvus_vectors(),使用 asyncio.gather 并行删除三类 Milvus 向量索引: - EpisodicMemoryMilvusRepository.delete_by_filters(user_id, group_id) - ForesightMilvusRepository.delete_by_filters(user_id, group_id) - EventLogMilvusRepository.delete_by_filters(user_id, group_id) - 若携带 event_id,额外精确删除: - episodic_repo.delete_by_event_id(event_id) - foresight_repo.delete_by_parent_id(event_id) - event_log_repo.delete_by_parent_id(event_id) - Milvus 清理失败仅 warning 日志,不影响主流程返回成功 (MongoDB 侧已成功是主要保证,向量清理失败不应回滚)
实时阶段(REALTIME_EVENT_LOG_ONLY=true): 每条消息立即提取 event_log(原子事实不依赖多轮上下文) 跳过 episodic memory 和 foresight 提取 event_log 以 MemCell 为 parent 直接存储(parent_type=memcell) 批处理阶段(BatchEpisodeWorker): 后台定时任务每 N 分钟扫描一次(默认 15 分钟) 收集同一 group 的多个 MemCell 合并为完整上下文窗口 调用 episode LLM 生成高质量叙事记忆 处理完成后在 MemCell.extend 中标记 batch_ep_done=True 新文件: biz_layer/mem_batch_episode_worker.py — BatchEpisodeWorker 类 core/lifespan/batch_episode_lifespan.py — 应用启动时自动注册 Worker 相关环境变量: REALTIME_EVENT_LOG_ONLY=true 启用两阶段模式 BATCH_EPISODE_INTERVAL=15 Worker 运行间隔(分钟) BATCH_EPISODE_LOOKBACK=120 向前查询窗口(分钟) BATCH_EPISODE_MIN_CELLS=3 触发生成的最少 MemCell 数
为MemCell排序使用的fallback datetime由naive的datetime.min 改为timezone-aware的datetime.min.replace(tzinfo=timezone.utc), 避免与带时区的MemCell.timestamp比较时抛出 TypeError: can't compare offset-naive and offset-aware datetimes
- docs/advanced/TWO_PHASE_EXTRACTION.md: 完整使用指南,含背景分析、 快速上手、参数配置、工作流程详解、与默认模式的对比表、已知限制 - docs/CHANGELOG.md: 新增 [Unreleased] 条目,说明本次变更内容
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Type of Change
Related Issues
Fixes #
Relates to #
Changes Made
Testing
Test Configuration:
Test Results:
Checklist
Screenshots (if applicable)
Additional Notes
Breaking Changes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.